<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Observers\RealEstatesObserver;

class RealEstates extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $guarded = [];
    protected $table = 'zfm_reals_estates';

    /**
     * 楼盘信息展示
     * @return mixed
     */
    public static function list()
    {
        return self::paginate(5);
    }

    /**
     * 楼盘信息查找
     * @param $where
     * @return mixed
     */
    public static function Seek($field, $where)
    {
        return self::where($field, 'like', "%$where%")->get();
    }

    /**
     * 楼盘信息删除
     */
    public static function del($id, $fangId)
    {
        return self::where([$id => $fangId])
            ->delete();
    }

    /**
     * 楼盘详情信息
     */
    public static function detail($field, $where)
    {
        return self::where($field, $where)->first();
    }

    /**
     * 楼盘信息修改
     */
    public static function change($field, $fangID, $SecondaryMessageUpdated)
    {
        $update = self::where($field, $fangID, $fangID)->first();
        return $update->fill($SecondaryMessageUpdated)
            ->save();

    }

    public static function boot()
    {
        parent::boot();
        self::observe(RealEstatesObserver::class);
    }

    /**
     * 楼盘信息删除
     */
    public static function RealEstatesSave($id, $fangId)
    {
        return self::where([$id => $fangId])
            ->delete();
    }


    public static function realId($id, $where)
    {
        return self::query()->where($id, $where)->first();
    }


}
